package littlepicture.control.delegates
{
	import littlepicture.pojo.Record;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.remoting.RemoteObject;
	
	public class ProjectDelegate
	{
		private var _service:RemoteObject;
		private var _responder:IResponder;
		
		static private var _projectDelegate:ProjectDelegate;
		
		static private var REMOTE_OBJECT_DESTINATION:String="MainService";
		
		static public function getInstance(responder:IResponder):ProjectDelegate{
			if(_projectDelegate == null){
				_projectDelegate = new ProjectDelegate();
			}
			_projectDelegate._responder = responder;
			
			return _projectDelegate;
		}
		
		public function ProjectDelegate()
		{
            _service=new RemoteObject(REMOTE_OBJECT_DESTINATION);
		}
		
		public function loadProject(date:Date):void{
			var token:AsyncToken = _service.getLpProject(date);
			token.addResponder(_responder);
		}	

		public function addWorkRecord(employeeId:int, date:Date, record:Record):void{
			var token:AsyncToken = _service.addWorkRecordForPerson(employeeId, date, record);
			token.addResponder(_responder);
		}
		
		public function updateWorkRecord(record:Record):void{
			var token:AsyncToken = _service.updateWorkRecord(record);
			token.addResponder(_responder);
		}
		
		public function deleteWorkRecord(recordId:Number):void{
			var token:AsyncToken = _service.deleteWorkRecordById(recordId);
			token.addResponder(_responder);
		}
		
	}
}